<?php

/**
 * 邮件发送
 */
function post_email($title, $html, $to = array('think889977@sina.com')) {
    $mail = new PHPMailer();

    $smtpserver = "smtp.sina.com";
    $smtpusermail = "kingphp@sina.com";
    $smtpusername = "kingphp@sina.com";
    $smtpuser = "kingphp@sina.com";
    $smtppass = "kingphp@123";

    $mailsubject = $title;
    $mailbody = $html;

    $mail->IsSMTP();        // send via SMTP
    $mail->Host = $smtpserver;   // SMTP servers
    $mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username = $smtpuser;   // SMTP username
    $mail->Password = $smtppass;   // SMTP password
    $mail->CharSet = "UTF-8";

    $mail->From = $smtpusermail;
    $mail->FromName = $smtpusername;

    if (is_array($to)) {
        foreach ($to as $t) {
            $mail->AddAddress($t);
        }
    } else {
        $mail->AddAddress($to);
    }

    $mail->WordWrap = 100; // set word wrap
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = $mailsubject;
    $mail->Body = $mailbody;
    $mail->AltBody = $mailbody;
    return $mail->Send();
}

/**
 * 邮件发送
 */
function send_email($smtpserver, $smtpusermail, $smtpusername, $smtpuser, $smtppass, $title = '标题', $html = '邮件内容', $to = array('think889977@sina.com')) {
    $mail = new PHPMailer();

    $mailsubject = $title;
    $mailbody = $html;

    $mail->IsSMTP();        // send via SMTP
    $mail->Host = $smtpserver;   // SMTP servers
    $mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username = $smtpuser;   // SMTP username
    $mail->Password = $smtppass;   // SMTP password
    $mail->CharSet = "UTF-8";

    $mail->From = $smtpusermail;
    $mail->FromName = $smtpusername;

    if (is_array($to)) {
        foreach ($to as $t) {
            $mail->AddAddress($t);
        }
    } else {
        $mail->AddAddress($to);
    }

    $mail->WordWrap = 100; // set word wrap
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = $mailsubject;
    $mail->Body = $mailbody;
    $mail->AltBody = $mailbody;
    return $mail->Send();
}

function send_sms($mobile, $content) {
    if (!defined('PHPCMS_SMS_UID')) {
        log::dw('PHPCMS_SMS_UID:' . PHPCMS_SMS_UID);
        return false;
    }
    $tplid = 16;
    $send_txt = mb_substr($content, 0, 60, 'UTF-8');
    $sms_uid = PHPCMS_SMS_UID;
    $sms_pid = PHPCMS_SMS_PID;
    $sms_passwd = PHPCMS_SMS_PASSWD;
    $url = "http://sms.phpcms.cn/api.php?op=sms_service&sms_uid=$sms_uid&sms_pid=$sms_pid&sms_passwd=$sms_passwd&mobile=$mobile&send_txt=" . urlencode($send_txt) . "&charset=utf-8&tplid=" . $tplid;
    snoopy_fetch($url);
}

?>